import 'dart:math';

import 'package:flutter/material.dart';
import 'package:xindong/extension/extension_string.dart';

class DZColors {
  // 透明色
  static const Color clear = Colors.transparent;

  // 白色
  static const Color white = Colors.white;

  // 黑色
  static const Color black = Colors.black;

  static const Color appBar = Color(0xFFFFFFFF);
  static const Color tabBar = Color(0xFFFFFFFF);

  static const Color white50 = Color(0x80FFFFFF);

  // 弹窗
  static const Color dialog = Color(0xFFEEEEEE);

  // UI主色
  static const Color mainColor = Color(0xFFD450F1);

  // UI主色 - 蓝
  static const Color mainBlueColor = Color(0xFFEF7AB6);

  // UI主色 - 浅色
  static const Color mainLightColor = Color(0x80D450F1);

  // UI主色 - 钱
  static const Color moneyColor = Colors.orange;

  // UI遮挡蒙层颜色
  static const Color maskColor = Color(0xb2000000);

  // 背景颜色
  static const Color backgroundColor = Color(0xFFF0F0F0);

  // 图片覆盖颜色
  static const Color coverColor = Color(0xFFDDDDDD);

  // 使能禁用颜色60%
  static Color disabledColor = mainColor.withOpacity(0.6);

  // 禁用颜色60%
  static const Color disabledGreyColor = Colors.grey;

  // 禁用文字颜色
  static const Color disabledTextColor = Color(0x99FFFFFF);

  // 使能禁用颜色开关
  static const Color disabledSwitchColor = Color(0xFFF0F0F0);

  // 标题黑色颜色
  static const Color titleColor = Color(0xFF333333);

  // 内容灰色颜色
  static const Color contentColor = Color(0xFF666666);

  // 占位符颜色
  static const Color placeholderColor = Color(0xFF999999);

  // 分割线颜色
  static const Color dividerColor = Color(0xFFDDDDDD);

  // Cell颜色
  static const Color cellColor = Color(0xFFFFFFFF);

  // 分组颜色
  static const Color sectionColor = Color(0xFFF0F0F0);

  // 按住说话颜色
  static const Color downColor = Color(0xFFE6E6E6);

  // 灰色阴影颜色
  static const Color shadowColor = Color(0xFFD0D2D7);

  // 灰色阴影颜色
  static const Color transparentButtonColor = Colors.black26;

  // 静态变量设置方式，要先init()

  // 正确颜色
  static late Color statusCorrectColor;

  // 错误颜色
  static late Color statusIncorrectColor;

  // 初始化全局信息，会在APP启动时执行
  static Future init() async {
    statusCorrectColor = DZColors.hexColor(0x6CDA76, alpha: 1);
    statusIncorrectColor = DZColors.hexColor(0xF03E3E, alpha: 1);
  }

  // 十六进制颜色
  //
  // hex, 十六进制值，例如：0xFFFFFF,
  // alpha, 透明度 [0.0, 1.0]
  static Color hexColor(int hex, {double alpha = 1.0}) {
    alpha = max(0.0, min(alpha, 1.0));
    return Color.fromRGBO((hex & 0xFF0000) >> 16, (hex & 0x00FF00) >> 8, (hex & 0x0000FF) >> 0, alpha);
  }

  // 十六进制颜色
  //
  // hexString 十六进制值字符串，如："000000","#FFFFFF"
  // alpha, 透明度 [0.0, 1.0]
  static Color hexStringColor(String hexString, {double alpha = 1.0}) {
    alpha = max(0.0, min(alpha, 1.0));
    hexString = hexString.matchHexColor;
    return Color(int.parse(hexString, radix: 16)).withOpacity(alpha);
  }
}
